package com.wootion.cims.module.systemsetting.community.controller;

import com.wootion.cims.module.systemsetting.community.service.SysCommunityService;
import com.wootion.cims.module.systemsetting.community.model.SysCommunity;
import com.wootion.cims.module.systemsetting.dictionary.model.LogAnotion;
import com.wootion.cims.response.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.http.HttpRequest;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author: LanQiang
 * @Date: 2022/11/21/11:23
 * @Description: 作用xxx
 */
@Slf4j
@RequestMapping(value = {"/community"})
@RestController
@RequiresAuthentication
@Api(value = "社区管理")
public class SysCommunityController {
    
    @Resource
    private SysCommunityService sysCommunityService;

    /**
     * 查询所有社区信息/或条件查询,并分页返回
     * @param condition
     * @param limit
     * @param page
     * @return
     */
    @PostMapping(path = {"/list"})
    @ApiOperation(value = "社区管理-社区列表查询", httpMethod = "POST", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,notes = "如果需要按照条件查询就传入condition社区名称关键字,condition是字符串类型,不是jso格式,而是K-V结构,例如：condition:阳光社区 page:2 limit:20")
    public ResponseResult list(@RequestParam(required = false) String condition,
                                        @RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "18") Integer limit){
        return sysCommunityService.list(condition,page,limit);
    }

    /**
     * 修改社区
     * @param sysCommunity
     * @return
     */
    @LogAnotion(type = "修改",value = "0",incident = "社区信息",prefixContent = "社区名称")
    @PostMapping(path = {"/update"},consumes = {MediaType.APPLICATION_JSON_VALUE})
    @ApiOperation(value = "社区管理-修改社区", httpMethod = "POST", consumes = MediaType.APPLICATION_JSON_VALUE,notes = "{\"name\":\"桃园社区\",\"principal\":\"约翰\",\"tel\":\"56789452\",\"address\":\"成华大道二仙桥\"}")
    public ResponseResult update(@RequestBody @Validated SysCommunity sysCommunity){
        return sysCommunityService.update(sysCommunity);
    }

    /**
     * 新增社区
     * @param sysCommunity
     * @return
     */
    @LogAnotion(type = "新增",value = "0",incident = "社区信息",prefixContent = "社区名称")
    @PostMapping(path = {"/save"},consumes = {MediaType.APPLICATION_JSON_VALUE})
    @ApiOperation(value = "社区管理-新增社区", httpMethod = "POST", consumes = MediaType.APPLICATION_JSON_VALUE,notes = "{\"name\":\"桃园社区\",\"principal\":\"约翰\",\"tel\":\"56789452\",\"address\":\"成华大道二仙桥\"}")
    public ResponseResult save(@RequestBody @Validated SysCommunity sysCommunity){
        return sysCommunityService.save(sysCommunity);
    }

    /**
     * 删除社区
     * @param sysCommunity
     * @return
     */
    @LogAnotion(type = "删除",value = "0",incident = "社区信息",prefixContent = "社区名称")
    @PostMapping(path = {"/delete"},consumes = {MediaType.APPLICATION_JSON_VALUE})
    @ApiOperation(value = "社区管理-删除社区", httpMethod = "POST", consumes = MediaType.APPLICATION_JSON_VALUE,notes = "{\"id\":\"1\"}")
    public ResponseResult delete(@RequestBody SysCommunity sysCommunity){
        return sysCommunityService.deleteCommunity(sysCommunity);
    }
}
